package org.wlw.proxy;

import org.wlw.anno.AuthAnno;
import org.wlw.anno.LogAnno;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/*
 * 动态代理对象
 * */
public class BaseProxyObject implements InvocationHandler {
    private Object target;

    public BaseProxyObject(Object target) {
        this.target = target;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.isAnnotationPresent(AuthAnno.class))
            System.out.println("权限控制");
        Object rel = method.invoke(target, args);
        if (method.isAnnotationPresent(LogAnno.class))
            System.out.println("日志控制");
        return rel;
    }
}
